package com.blrs.web.controller.system;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.blrs.common.annotation.RepeatSubmit;
import com.blrs.system.domain.SysUpload;
import com.blrs.system.service.ISysUploadService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 附件类型Controller
 * 
 * @author yuxiang.chen
 * @date 2023-07-20
 */
@RestController
@RequestMapping("/system/sysupload")
public class SysUploadController  extends BaseController
{
    @Autowired
    private ISysUploadService sysUploadService;
    //单个文件大小
    @Value("${spring.servlet.multipart.max-file-size}")
    private String singleSize;
    //总上传的文件大小
    @Value("${spring.servlet.multipart.max-request-size}")
    private String allSize;
    /**
     * 查询附件类型列表
     */
    //@PreAuthorize("@ss.hasPermi('system:upload:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUpload sysUpload)
    {
        startPage();
        List<SysUpload> list = sysUploadService.selectSysUploadList(sysUpload);
        return getDataTable(list);
    }

    /**
     * 导出附件类型列表
     */
    //@PreAuthorize("@ss.hasPermi('system:upload:export')")
    @Log(title = "附件类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUpload sysUpload)
    {
        List<SysUpload> list = sysUploadService.selectSysUploadList(sysUpload);
        ExcelUtil<SysUpload> util = new ExcelUtil<SysUpload>(SysUpload.class);
        util.exportExcel(response, list, "附件类型数据");
    }

    /**
     * 获取附件类型详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:upload:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(sysUploadService.selectSysUploadById(id));
    }

    /**
     * 新增附件类型
     */
    //@PreAuthorize("@ss.hasPermi('system:upload:add')")
    @Log(title = "附件类型", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit(interval = 1000,message = "请勿重复提交！")
    public AjaxResult add(@RequestBody SysUpload sysUpload)
    {
        return toAjax(sysUploadService.insertSysUpload(sysUpload));
    }

    /**
     * 修改附件类型
     */
    //@PreAuthorize("@ss.hasPermi('system:upload:edit')")
    @Log(title = "附件类型", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit(interval = 1000,message = "请勿重复提交！")
    public AjaxResult edit(@RequestBody SysUpload sysUpload)
    {
        return toAjax(sysUploadService.updateSysUpload(sysUpload));
    }

    /**
     * 删除附件类型
     */
    //@PreAuthorize("@ss.hasPermi('system:upload:remove')")
    @Log(title = "附件类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{Ids}")
    public AjaxResult remove(@PathVariable String[] Ids)
    {
        return toAjax(sysUploadService.deleteSysUploadByIds(Ids));
    }

    /**
     * 获取文件类型
     * @param businessCode 类型编号
     * @return
     */
    //@PreAuthorize("@ss.hasPermi('system:upload:query')")
    @GetMapping(value = "/businessCode/{businessCode}")
    public AjaxResult selectSysUploadByCode(@PathVariable("businessCode") String businessCode){
        return success(sysUploadService.selectSysUploadByCode(businessCode));
    }
    @GetMapping(value = "/fileSize")
    public AjaxResult fileSize(){
        Map map=new HashMap();
        map.put("singleSize",this.singleSize);
        map.put("allSize",this.allSize);
        return success(map);
    }
}
